home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / TGE133.ZIP;1 / DEMO / TGEDEMO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  32.6 KB  |  968 lines

  1. /**************************************************************************
  2. *  File:        TGEDEMO.CPP   Copyright (c) 1993-1994 by Matthew Hildebrand
  3. *
  4. *  Purpose:     Demonstrate TGE 1.33's features.
  5. **************************************************************************/
  6.  
  7. #include <alloc.h>
  8. #include <conio.h>
  9. #include <dos.h>
  10. #include <mem.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "..\include\tge.h"
  14. #include "..\include\tgemouse.h"
  15. #include "..\include\varfont.h"
  16. #include "..\include\vcoord.h"
  17.  
  18. #define TGELOGO_FILENAME    "TGELOGO.RAW"
  19. #define FONT_FILENAME       "BIGTEXT.FNT"
  20. #define QUIT_IF_ESCAPE      if (getKey() == 27)  \
  21.                               exit(EXIT_SUCCESS)
  22.  
  23. enum
  24. {
  25.   Center, BottomCenter
  26. };
  27.  
  28. void setup(int argc, char *argv[]);
  29. void printMessage(char *string, int where=BottomCenter);
  30. void lineDemo(void);
  31. void putPixelDemo(void);
  32. void drawRectDemo(void);
  33. void filledRectDemo(void);
  34. void ellipseDemo(void);
  35. void filledEllipseDemo(void);
  36. void circleDemo(void);
  37. void filledCircleDemo(void);
  38. void putImageDemo(void);
  39. void fontDemo(void);
  40. void viewportDemo(void);
  41. void paletteDemo(void);
  42. void scaleBitmapDemo(void);
  43. void mouseDemo(void);
  44. void signOff(void);
  45. int getKey(void);
  46. void waitVerticalRetrace(void);
  47.  
  48. VariableFont font;
  49. void far *tgeLogo;
  50. unsigned char palette[] =
  51. {
  52.     0,   0,   0,   0,   0, 168,   0, 168,   0,   0, 168, 168,
  53.   168,   0,   0, 168,   0, 168, 168,  84,   0, 168, 168, 168,
  54.    84,  84,  84,  84,  84, 252,  84, 252,  84,  84, 252, 252,
  55.   252,  84,  84, 252,  84, 252, 252, 252,  84, 252, 252, 252,
  56.     0,   0,   0,  20,  20,  20,  32,  32,  32,  44,  44,  44,
  57.    56,  56,  56,  68,  68,  68,  80,  80,  80,  96,  96,  96,
  58.   112, 112, 112, 128, 128, 128, 144, 144, 144, 160, 160, 160,
  59.   180, 180, 180, 200, 200, 200, 224, 224, 224, 252, 252, 252,
  60.     0,   0, 252,  64,   0, 252, 124,   0, 252, 188,   0, 252,
  61.   252,   0, 252, 252,   0, 188, 252,   0, 124, 252,   0,  64,
  62.   252,   0,   0, 252,  64,   0, 252, 124,   0, 252, 188,   0,
  63.   252, 252,   0, 188, 252,   0, 124, 252,   0,  64, 252,   0,
  64.     0, 252,   0,   0, 252,  64,   0, 252, 124,   0, 252, 188,
  65.     0, 252, 252,   0, 188, 252,   0, 124, 252,   0,  64, 252,
  66.   124, 124, 252, 156, 124, 252, 188, 124, 252, 220, 124, 252,
  67.   252, 124, 252, 252, 124, 220, 252, 124, 188, 252, 124, 156,
  68.   252, 124, 124, 252, 156, 124, 252, 188, 124, 252, 220, 124,
  69.   252, 252, 124, 220, 252, 124, 188, 252, 124, 156, 252, 124,
  70.   124, 252, 124, 124, 252, 156, 124, 252, 188, 124, 252, 220,
  71.   124, 252, 252, 124, 220, 252, 124, 188, 252, 124, 156, 252,
  72.   180, 180, 252, 196, 180, 252, 216, 180, 252, 232, 180, 252,
  73.   252, 180, 252, 252, 180, 232, 252, 180, 216, 252, 180, 196,
  74.   252, 180, 180, 252, 196, 180, 252, 216, 180, 252, 232, 180,
  75.   252, 252, 180, 232, 252, 180, 216, 252, 180, 196, 252, 180,
  76.   180, 252, 180, 180, 252, 196, 180, 252, 216, 180, 252, 232,
  77.   180, 252, 252, 180, 232, 252, 180, 216, 252, 180, 196, 252,
  78.     0,   0, 112,  28,   0, 112,  56,   0, 112,  84,   0, 112,
  79.   112,   0, 112, 112,   0,  84, 112,   0,  56, 112,   0,  28,
  80.   112,   0,   0, 112,  28,   0, 112,  56,   0, 112,  84,   0,
  81.   112, 112,   0,  84, 112,   0,  56, 112,   0,  28, 112,   0,
  82.     0, 112,   0,   0, 112,  28,   0, 112,  56,   0, 112,  84,
  83.     0, 112, 112,   0,  84, 112,   0,  56, 112,   0,  28, 112,
  84.    56,  56, 112,  68,  56, 112,  84,  56, 112,  96,  56, 112,
  85.   112,  56, 112, 112,  56,  96, 112,  56,  84, 112,  56,  68,
  86.   112,  56,  56, 112,  68,  56, 112,  84,  56, 112,  96,  56,
  87.   112, 112,  56,  96, 112,  56,  84, 112,  56,  68, 112,  56,
  88.    56, 112,  56,  56, 112,  68,  56, 112,  84,  56, 112,  96,
  89.    56, 112, 112,  56,  96, 112,  56,  84, 112,  56,  68, 112,
  90.    80,  80, 112,  88,  80, 112,  96,  80, 112, 104,  80, 112,
  91.   112,  80, 112, 112,  80, 104, 112,  80,  96, 112,  80,  88,
  92.   112,  80,  80, 112,  88,  80, 112,  96,  80, 112, 104,  80,
  93.   112, 112,  80, 104, 112,  80,  96, 112,  80,  88, 112,  80,
  94.    80, 112,  80,  80, 112,  88,  80, 112,  96,  80, 112, 104,
  95.    80, 112, 112,  80, 104, 112,  80,  96, 112,  80,  88, 112,
  96.     0,   0,  64,  16,   0,  64,  32,   0,  64,  48,   0,  64,
  97.    64,   0,  64,  64,   0,  48,  64,   0,  32,  64,   0,  16,
  98.    64,   0,   0,  64,  16,   0,  64,  32,   0,  64,  48,   0,
  99.    64,  64,   0,  48,  64,   0,  32,  64,   0,  16,  64,   0,
  100.     0,  64,   0,   0,  64,  16,   0,  64,  32,   0,  64,  48,
  101.     0,  64,  64,   0,  48,  64,   0,  32,  64,   0,  16,  64,
  102.    32,  32,  64,  40,  32,  64,  48,  32,  64,  56,  32,  64,
  103.    64,  32,  64,  64,  32,  56,  64,  32,  48,  64,  32,  40,
  104.    64,  32,  32,  64,  40,  32,  64,  48,  32,  64,  56,  32,
  105.    64,  64,  32,  56,  64,  32,  48,  64,  32,  40,  64,  32,
  106.    32,  64,  32,  32,  64,  40,  32,  64,  48,  32,  64,  56,
  107.    32,  64,  64,  32,  56,  64,  32,  48,  64,  32,  40,  64,
  108.    44,  44,  64,  48,  44,  64,  52,  44,  64,  60,  44,  64,
  109.    64,  44,  64,  64,  44,  60,  64,  44,  52,  64,  44,  48,
  110.    64,  44,  44,  64,  48,  44,  64,  52,  44,  64,  60,  44,
  111.    64,  64,  44,  60,  64,  44,  52,  64,  44,  48,  64,  44,
  112.    44,  64,  44,  44,  64,  48,  44,  64,  52,  44,  64,  60,
  113.    44,  64,  64,  44,  60,  64,  44,  52,  64,  44,  48,  64,
  114.     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  115.     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0
  116. };
  117.  
  118.  
  119.  
  120. /**************************************************************************
  121. *  Function:    main
  122. *
  123. *  Purpose:     Program entry point.
  124. *
  125. *  Entry:       argc = Number of parameters - 1.
  126. *               argv = Array containing the actual parameters.
  127. *
  128. *  Exit:        N/A
  129. **************************************************************************/
  130.  
  131. void main(int argc, char *argv[])
  132. {
  133.   //*** Set things up
  134.   setup(argc, argv);
  135.  
  136.   //*** Run the demos
  137.   lineDemo();
  138.   putPixelDemo();
  139.   drawRectDemo();
  140.   filledRectDemo();
  141.   ellipseDemo();
  142.   filledEllipseDemo();
  143.   circleDemo();
  144.   filledCircleDemo();
  145.   putImageDemo();
  146.   fontDemo();
  147.   viewportDemo();
  148.   paletteDemo();
  149.   scaleBitmapDemo();
  150.   mouseDemo();
  151.  
  152.   //*** Get a key before quitting
  153.   getKey();
  154. }
  155.  
  156.  
  157.  
  158. /**************************************************************************
  159. *  Function:    setup
  160. *
  161. *  Purpose:     Load drivers and fonts, and do other setup things.
  162. *
  163. *  Entry:       argc = Number of parameters - 1.
  164. *               argv = Array containing the actual parameters.
  165. *
  166. *  Exit:        If an error occurs, the program will exit from within this
  167. *               function.
  168. **************************************************************************/
  169.  
  170. void setup(int argc, char *argv[])
  171. {
  172.   //*** Parse command line
  173.   if (argc != 2)
  174.   {
  175.     printf("TGEDEMO 1.33  Copyright (c) 1993-1994 by Matthew Hildebrand\n\n"
  176.            "        Usage:  TGEDEMO driver[.drv]\n\n"
  177.            "     Examples:  tgedemo 320x200\n"
  178.            "                tgedemo ..\\drivers\\640x480.drv\n"
  179.            "                tgedemo d:\\tge\\drivers\\360x480\n\n"
  180.            "         Note:  If you are running TGEDEMO for the first time,\n"
  181.            "                you will need to initialize the TGEDRIVERS and\n"
  182.            "                TGEFONTS environment variables.  Refer to\n"
  183.            "                TGEDEMO.DOC for details.\n\n");
  184.     exit(EXIT_FAILURE);
  185.   }
  186.   clrscr();                                 // clear the screen
  187.  
  188.   //*** Load the specified graphics driver
  189.   switch (loadGraphDriver(argv[1]))
  190.   {
  191.     case TGE_SUCCESS:                       // success
  192.       break;
  193.     case TGE_OPEN_ERR:                      // file not found
  194.       printf("Error opening driver file %s; aborting.\n\n"
  195.              "Please ensure that the file specified is spelled correctly, and that the\n"
  196.              "TGEDRIVERS environment variable has been set to point to the TGE drivers\n"
  197.              "directory; refer to TGEDEMO.DOC for more information.\n\n",
  198.              argv[1]);
  199.       exit(EXIT_FAILURE);
  200.     case TGE_FORMAT_ERR:                    // not a TGE driver
  201.       printf("Format error processing file %s; aborting.\n\n", argv[1]);
  202.       exit(EXIT_FAILURE);
  203.     case TGE_ALLOC_ERR:                     // out of memory
  204.       printf("Insufficient memory; aborting.\n\n");
  205.       exit(EXIT_FAILURE);
  206.     case TGE_FILE_ERR:                      // file read error
  207.       printf("Error reading file %s; aborting.\n\n", argv[1]);
  208.       exit(EXIT_FAILURE);
  209.     default:                                // who knows?
  210.       printf("Unknown error loading driver %s; aborting.\n\n", argv[1]);
  211.       exit(EXIT_FAILURE);
  212.   }
  213.   atexit(unloadGraphDriver);                // unload driver on exit
  214.  
  215.   //*** Load the TGE logo bitmap
  216.   tgeLogo = loadRawFile(TGELOGO_FILENAME);  // load it
  217.   if (tgeLogo == NULL)                      // check for errors
  218.   {
  219.     printf("Error loading bitmap file %s; aborting.\n\n", TGELOGO_FILENAME);
  220.     exit(EXIT_FAILURE);
  221.   }
  222.  
  223.   //*** Switch to graphics mode
  224.   if (!initGraphics())                      // initialize graphics mode
  225.   {
  226.     printf("Unable to initialize graphics hardware; aborting.\n\n"
  227.            "Try installing the Universal VESA TSR before running this\n"
  228.            "program again; refer to UNIVESA.DOC for more information.\n\n");
  229.     exit(EXIT_FAILURE);
  230.   }
  231.   setBlockPalette(0, 255, palette);         // set the palette
  232.  
  233.   //*** Load the font
  234.   if (font.load(FONT_FILENAME) == 0)
  235.   {
  236.     deInitGraphics();
  237.     printf("Error loading font file %s; aborting.\n\n"
  238.            "Please ensure that the file specified is spelled correctly, and that the\n"
  239.            "TGEFONTS environment variable has been set to point to the TGE fonts\n"
  240.            "directory; refer to TGEDEMO.DOC for more information.\n\n",
  241.            FONT_FILENAME);
  242.     exit(EXIT_FAILURE);
  243.   }
  244.  
  245.   //*** Seed the random number generator
  246.   randomize();
  247.  
  248.   //*** Sign off before exit
  249.   atexit(signOff);                          // display sign-off message
  250.   atexit(deInitGraphics);                   // restore text mode
  251. }
  252.  
  253.  
  254.  
  255. /**************************************************************************
  256. *  Function:    printMessage
  257. *
  258. *  Purpose:     Print a one-line message centered on the screen.
  259. *
  260. *  Entry:       string = Message to display
  261. *               where = Flag indicating where to display message.  Can be
  262. *                       Center or BottomCenter.
  263. *
  264. *  Exit:        N/A
  265. **************************************************************************/
  266.  
  267. void printMessage(char *string, int where)
  268. {
  269.   switch (where)
  270.   {
  271.     case Center:
  272.       font.put(((OUTVIEWPORTLRX-OUTVIEWPORTULX+1-font.width(string)) / 2),
  273.               ((OUTVIEWPORTLRY-OUTVIEWPORTULY+1-font.maxHeight()) / 2),
  274.                string);
  275.       break;
  276.     case BottomCenter:
  277.       font.put(((OUTVIEWPORTLRX-OUTVIEWPORTULX+1-font.width(string)) / 2),
  278.                OUTVIEWPORTLRY-font.maxHeight(),
  279.                string);
  280.       break;
  281.     default:
  282.       ;
  283.   }
  284. }
  285.  
  286.  
  287.  
  288. /**************************************************************************
  289. *  Function:    lineDemo
  290. *
  291. *  Purpose:     Demonstrate line().
  292. *
  293. *  Entry:       N/A
  294. *
  295. *  Exit:        N/A
  296. **************************************************************************/
  297.  
  298. void lineDemo(void)
  299. {
  300.   static char message[] = "TGE can draw lines...";
  301.   int maxY, count;
  302.  
  303.   //*** Set up the message
  304.   printMessage(message);                    // print it
  305.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  306.  
  307.   //*** Draw lines until a key is struck
  308.   while (!kbhit())
  309.   {
  310.     for (count=0; count<100; count++)
  311.       line(random(OUTMAXX+1), random(maxY),
  312.            random(OUTMAXX+1), random(maxY),
  313.            random(MAXCOLOUR+1));
  314.   }
  315.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  316. }
  317.  
  318.  
  319.  
  320. /**************************************************************************
  321. *  Function:    putPixelDemo
  322. *
  323. *  Purpose:     Demonstrate putPixel().
  324. *
  325. *  Entry:       N/A
  326. *
  327. *  Exit:        N/A
  328. **************************************************************************/
  329.  
  330. void putPixelDemo(void)
  331. {
  332.   static char message[] = "pixels...";
  333.   int maxY, count;
  334.  
  335.   //*** Set up the message
  336.   clearGraphics(0);                         // clear screen to black
  337.   printMessage(message);                    // print it
  338.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  339.  
  340.   //*** Draw pixels until a key is struck
  341.   while (!kbhit())
  342.   {
  343.     for (count=0; count<2000; count++)
  344.       putPixel(random(OUTMAXX+1), random(maxY), random(MAXCOLOUR+1));
  345.   }
  346.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  347. }
  348.  
  349.  
  350.  
  351. /**************************************************************************
  352. *  Function:    drawRectDemo
  353. *
  354. *  Purpose:     Demonstrate drawRect().
  355. *
  356. *  Entry:       N/A
  357. *
  358. *  Exit:        N/A
  359. **************************************************************************/
  360.  
  361. void drawRectDemo(void)
  362. {
  363.   static char message[] = "rectangles...";
  364.   int maxY, count;
  365.  
  366.   //*** Set up the message
  367.   clearGraphics(0);                         // clear screen to black
  368.   printMessage(message);                    // print it
  369.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  370.  
  371.   //*** Draw rectangles until a key is struck
  372.   while (!kbhit())
  373.   {
  374.     for (count=0; count<100; count++)
  375.       drawRect(random(OUTMAXX+1), random(maxY),
  376.                random(OUTMAXX+1), random(maxY),
  377.                random(MAXCOLOUR+1));
  378.   }
  379.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  380. }
  381.  
  382.  
  383.  
  384. /**************************************************************************
  385. *  Function:    filledRectDemo
  386. *
  387. *  Purpose:     Demonstrate filledRectDemo().
  388. *
  389. *  Entry:       N/A
  390. *
  391. *  Exit:        N/A
  392. **************************************************************************/
  393.  
  394. void filledRectDemo(void)
  395. {
  396.   static char message[] = "filled rectangles...";
  397.   int maxY, count;
  398.  
  399.   //*** Set up the message
  400.   clearGraphics(0);                         // clear screen to black
  401.   printMessage(message);                    // print it
  402.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  403.  
  404.   //*** Draw filled rectangles until a key is struck
  405.   while (!kbhit())
  406.   {
  407.     for (count=0; count<15; count++)
  408.       filledRect(random(OUTMAXX+1), random(maxY),
  409.                  random(OUTMAXX+1), random(maxY),
  410.                  random(MAXCOLOUR+1));
  411.   }
  412.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  413. }
  414.  
  415.  
  416.  
  417. /**************************************************************************
  418. *  Function:    ellipseDemo
  419. *
  420. *  Purpose:     Demonstrate ellipse().
  421. *
  422. *  Entry:       N/A
  423. *
  424. *  Exit:        N/A
  425. **************************************************************************/
  426.  
  427. void ellipseDemo(void)
  428. {
  429.   static char message[] = "ellipses...";
  430.   int maxY, count;
  431.  
  432.   //*** Set up the message
  433.   clearGraphics(0);                         // clear screen to black
  434.   printMessage(message);                    // print it
  435.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  436.  
  437.   //*** Draw ellipses until a key is struck
  438.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  439.   while (!kbhit())
  440.   {
  441.     for (count=0; count<100; count++)
  442.       ellipse(random(OUTMAXX+1), random(OUTMAXY+1),
  443.               random((OUTMAXX+1)/8)*2+10, random((OUTMAXY+1)/8)*2+10,
  444.               random(MAXCOLOUR+1));
  445.   }
  446.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  447.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  448. }
  449.  
  450.  
  451.  
  452. /**************************************************************************
  453. *  Function:    filledEllipseDemo
  454. *
  455. *  Purpose:     Demonstrate filledEllipse().
  456. *
  457. *  Entry:       N/A
  458. *
  459. *  Exit:        N/A
  460. **************************************************************************/
  461.  
  462. void filledEllipseDemo(void)
  463. {
  464.   static char message[] = "filled ellipses...";
  465.   int maxY, count;
  466.  
  467.   //*** Set up the message
  468.   clearGraphics(0);                         // clear screen to black
  469.   printMessage(message);                    // print it
  470.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  471.  
  472.   //*** Draw filled ellipses until a key is struck
  473.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  474.   while (!kbhit())
  475.   {
  476.     for (count=0; count<30; count++)
  477.       filledEllipse(random(OUTMAXX+1), random(OUTMAXY+1),
  478.                     random((OUTMAXX+1)/8)*2+10, random((OUTMAXY+1)/8)*2+10,
  479.                     random(MAXCOLOUR+1));
  480.   }
  481.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  482.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  483. }
  484.  
  485.  
  486.  
  487. /**************************************************************************
  488. *  Function:    circleDemo
  489. *
  490. *  Purpose:     Demonstrate circle().
  491. *
  492. *  Entry:       N/A
  493. *
  494. *  Exit:        N/A
  495. **************************************************************************/
  496.  
  497. void circleDemo(void)
  498. {
  499.   static char message[] = "circles...";
  500.   int maxY, count;
  501.  
  502.   //*** Set up the message
  503.   clearGraphics(0);                         // clear screen to black
  504.   printMessage(message);                    // print it
  505.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  506.  
  507.   //*** Draw circles until a key is struck
  508.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  509.   while (!kbhit())
  510.   {
  511.     for (count=0; count<100; count++)
  512.       circle(random(OUTMAXX+1), random(OUTMAXY+1),
  513.              random((OUTMAXX+1)/8)+10,
  514.              random(MAXCOLOUR+1));
  515.   }
  516.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  517.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  518. }
  519.  
  520.  
  521.  
  522. /**************************************************************************
  523. *  Function:    filledCircleDemo
  524. *
  525. *  Purpose:     Demonstrate filledCircle().
  526. *
  527. *  Entry:       N/A
  528. *
  529. *  Exit:        N/A
  530. **************************************************************************/
  531.  
  532. void filledCircleDemo(void)
  533. {
  534.   static char message[] = "filled circles...";
  535.   int maxY, count;
  536.  
  537.   //*** Set up the message
  538.   clearGraphics(0);                         // clear screen to black
  539.   printMessage(message);                    // print it
  540.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  541.  
  542.   //*** Draw filled circles until a key is struck
  543.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  544.   while (!kbhit())
  545.   {
  546.     for (count=0; count<30; count++)
  547.       filledCircle(random(OUTMAXX+1), random(OUTMAXY+1),
  548.                    random((OUTMAXX+1)/8)+10,
  549.                    random(MAXCOLOUR+1));
  550.   }
  551.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  552.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  553. }
  554.  
  555.  
  556.  
  557. /**************************************************************************
  558. *  Function:    putImageDemo
  559. *
  560. *  Purpose:     Demonstrate putImage().
  561. *
  562. *  Entry:       N/A
  563. *
  564. *  Exit:        N/A
  565. **************************************************************************/
  566.  
  567. void putImageDemo(void)
  568. {
  569.   static char message[] = "images...";
  570.   int maxY, curX, curY;
  571.  
  572.   //*** Set up the message
  573.   clearGraphics(0);                         // clear screen to black
  574.   printMessage(message);                    // print it
  575.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  576.  
  577.   //*** Set the viewport to exclude the message area
  578.   setOutputViewport(0, 0, SCREENMAXX, maxY);
  579.  
  580.   //*** Draw the TGE logo all over the background
  581.   curY = -(((maxY+1)%imageHeight(tgeLogo)) / 2);    // starting y-coordinate
  582.   curX = -(((OUTMAXX+1)%imageWidth(tgeLogo)) / 2);  // starting x-coordinate
  583.   do
  584.   {
  585.     do
  586.     {
  587.       putImage(curX, curY, tgeLogo);        // draw the logo
  588.       curX += imageWidth(tgeLogo);          // update x-coordinate
  589.     }
  590.     while (curX <= OUTMAXX);
  591.     curY += imageHeight(tgeLogo);           // update y-coordinate
  592.     curX = -(((OUTMAXX+1)%imageWidth(tgeLogo)) / 2);  // starting x-coordinate
  593.   }
  594.   while (curY <= maxY);
  595.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  596.  
  597.   //*** Reset the viewport to cover the whole screen
  598.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);
  599. }
  600.  
  601.  
  602.  
  603. /**************************************************************************
  604. *  Function:    fontDemo
  605. *
  606. *  Purpose:     Demonstrate fonts.
  607. *
  608. *  Entry:       N/A
  609. *
  610. *  Exit:        N/A
  611. **************************************************************************/
  612.  
  613. void fontDemo(void)
  614. {
  615.   static char message[] = "and, of course, text.";
  616.  
  617.   //*** Set up the message
  618.   clearGraphics(0);                         // clear screen to black
  619.   printMessage(message, Center);            // print it
  620.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  621. }
  622.  
  623.  
  624.  
  625. /**************************************************************************
  626. *  Function:    viewportDemo
  627. *
  628. *  Purpose:     Demonstrate viewports.
  629. *
  630. *  Entry:       N/A
  631. *
  632. *  Exit:        N/A
  633. **************************************************************************/
  634.  
  635. void viewportDemo(void)
  636. {
  637.   static char message[] = "Output can be clipped.";
  638.   VirtualCoord virtScreen;
  639.   int x1, y1, x2, y2;
  640.  
  641.   //*** Set up the message
  642.   font.palette(1, 255, 255, 255);           // update font colour
  643.   clearGraphics(colourCloseTo(90,90,90));   // clear screen to black
  644.   printMessage(message);                    // print it
  645.  
  646.   //*** Configure the virtual coordinate system
  647.   virtScreen.virtParams(4, 4);
  648.   virtScreen.realParams(OUTMAXX, OUTMAXY);
  649.  
  650.   //*** Set the viewport to exclude the message area
  651.   x1 = virtScreen.realX(1);
  652.   y1 = virtScreen.realY(1);
  653.   x2 = virtScreen.realX(3);
  654.   y2 = virtScreen.realY(3);
  655.   setOutputViewport(x1, y1, x2, y2);
  656.   filledRect(x1, y1, x2, y2, colourCloseTo(0,0,0));
  657.  
  658.   //*** Draw random things at random places.
  659.   while (!kbhit())
  660.   {
  661.     switch (random(8))                      // choose a thing to draw
  662.     {
  663.       case 0:                               // line()
  664.     x1 = random(OUTMAXX+1);
  665.     y1 = random(OUTMAXY+1);
  666.     x2 = random(OUTMAXX+1);
  667.     y2 = random(OUTMAXY+1);
  668.     if (clipLine(&x1, &y1, &x2, &y2))
  669.           line(x1, y1, x2, y2, random(MAXCOLOUR+1));
  670.     break;
  671.       case 1:                               // ellipse()
  672.         ellipse(random(OUTMAXX+1), random(OUTMAXY+1),
  673.                 random(OUTMAXX/3), random(OUTMAXY/3),
  674.                 random(MAXCOLOUR+1));
  675.     break;
  676.       case 2:                               // filledEllipse();
  677.         filledEllipse(random(OUTMAXX+1), random(OUTMAXY+1),
  678.                       random(OUTMAXX/3), random(OUTMAXY/3),
  679.                       random(MAXCOLOUR+1));
  680.     break;
  681.       case 3:                               // circle()
  682.     circle(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX/3),
  683.                 random(MAXCOLOUR+1));
  684.     break;
  685.       case 4:                               // filledCircle()
  686.     filledCircle(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX/3),
  687.                 random(MAXCOLOUR+1));
  688.     break;
  689.       case 5:                               // putImageInv()
  690.     putImageInv(random(OUTMAXX+1), random(OUTMAXY+1), tgeLogo);
  691.     break;
  692.       case 6:                               // filledRect()
  693.     x1 = random(OUTMAXX+1);
  694.     y1 = random(OUTMAXY+1);
  695.     x2 = random(OUTMAXX+1);
  696.     y2 = random(OUTMAXY+1);
  697.     if (clipFilledRect(&x1, &y1, &x2, &y2))
  698.           filledRect(x1, y1, x2, y2, random(MAXCOLOUR+1));
  699.     break;
  700.       case 7:
  701.     drawRect(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX+1),
  702.                 random(OUTMAXY+1), random(MAXCOLOUR+1));
  703.     break;
  704.       default:
  705.     ;
  706.     }
  707.   }
  708.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  709.  
  710.   //*** Reset the viewport to cover the whole screen
  711.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);
  712. }
  713.  
  714.  
  715.  
  716. /**************************************************************************
  717. *  Function:    paletteDemo
  718. *
  719. *  Purpose:     Demonstrate palette fading and rotation.
  720. *
  721. *  Entry:       N/A
  722. *
  723. *  Exit:        N/A
  724. **************************************************************************/
  725.  
  726. void paletteDemo(void)
  727. {
  728.   static char message[] = "TGE has other powerful features...";
  729.   unsigned char inPal[768], outPal[768], targetPalA[768], targetPalB[768];
  730.   void *in, *out, *temp;
  731.   int count, stillFadingFlag=1;
  732.  
  733.   //*** Introduce the next two demos
  734.   clearGraphics(0);                         // clear screen to black
  735.   printMessage(message, Center);            // print it
  736.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  737.  
  738.   //*** Initialize the palettes
  739.   memcpy(targetPalA, palette, 768);         // copy target palette into buffer
  740.   memset(inPal, 0x00, 768);                 // black starting palette
  741.   setBlockPalette(0, 255, inPal);           // set palette to black
  742.  
  743.   //*** Fill the screen with horizontal lines
  744.   for (count=0; count<=OUTMAXY; count++)
  745.     horizLine(count, 0, OUTMAXX, count&0xFF);
  746.  
  747.   //*** Rotate the palette until a key is pressed
  748.   in = (void*) inPal;                       // point to input buffer
  749.   out = (void*) outPal;                     // point to output buffer
  750.   while (!kbhit())
  751.   {
  752.     if (stillFadingFlag)                    // fade the palette in
  753.     {
  754.       stillFadingFlag = fadePalette(1, in, out, (void*)targetPalA);
  755.       memcpy(in, out, 768);
  756.     }
  757.     delay(10);                              // delay for a bit
  758.     rotatePalette(1, in, out);              // rotate the palette
  759.     rotatePalette(1, targetPalA, targetPalB); // rotate target palette
  760.     memcpy(targetPalA, targetPalB, 768);    // update target palette
  761.     waitVerticalRetrace();                  // avoid flicker
  762.     setBlockPalette(0, 255, out);           // update the palette
  763.     temp = out;                             // swap input and output pointers
  764.     out = in;
  765.     in = temp;
  766.   }
  767.  
  768.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  769.   setBlockPalette(0, 255, palette);         // restore palette
  770. }
  771.  
  772.  
  773.  
  774. /**************************************************************************
  775. *  Function:    scaleBitmapDemo
  776. *
  777. *  Purpose:     Demonstrate scaleBitmap.
  778. *
  779. *  Entry:       N/A
  780. *
  781. *  Exit:        N/A
  782. **************************************************************************/
  783.  
  784. void scaleBitmapDemo(void)
  785. {
  786.   void far *image;
  787.   unsigned count;
  788.  
  789.   //*** Grab a block of memory
  790.   if ((image=farmalloc(imageSizeDim(200,200))) == NULL)
  791.   {
  792.     deInitGraphics();
  793.     printf("Insufficient memory; aborting.\n\n"
  794.            "Press a key to continue...");
  795.     getKey();
  796.     clrscr();
  797.     exit(EXIT_FAILURE);
  798.   }
  799.  
  800.   //*** Make image grow from center of screen
  801.   clearGraphics(0);                         // clear screen to black
  802.   for (count=1; count<=200&&!kbhit(); count++)
  803.   {
  804.     scaleBitmap(tgeLogo, count, count, image);       // scale it
  805.     putImage((MAXX+1-count)/2, (MAXY+1-count)/2, image); // draw it
  806.   }
  807.  
  808.   //*** Clean up and go home
  809.   farfree(image);                           // release memory
  810.   if (kbhit())                              // if a key was pressed, then
  811.     QUIT_IF_ESCAPE;                         // quit if ESC pressed
  812. }
  813.  
  814.  
  815.  
  816. /**************************************************************************
  817. *  Function:    mouseDemo
  818. *
  819. *  Purpose:     Demonstrate the use of the mouse.
  820. *
  821. *  Entry:       N/A
  822. *
  823. *  Exit:        N/A
  824. **************************************************************************/
  825.  
  826. void mouseDemo(void)
  827. {
  828.   int pointerNum;
  829.  
  830.   //*** Ensure that a mouse is installed
  831.   if (!resetMouse())
  832.   {
  833.     deInitGraphics();
  834.     printf("Microsoft or compatible mouse not detected.\n"
  835.        "The demo for definable, device-independent pointers will not be run.\n\n"
  836.        "Press a key to continue...");
  837.     getKey();
  838.     clrscr();
  839.     exit(EXIT_SUCCESS);
  840.   }
  841.  
  842.   //*** Initialize the mouse handler
  843.   initNewMouse();                           // initialize handler
  844.   setHorizLimitsMouse(0, OUTMAXX);          // set horizontal limits
  845.   setVertLimitsMouse(0, OUTMAXY);           // set vertical limits
  846.   setPosMouse(OUTMAXX/2, OUTMAXY/2);        // center pointer on-screen
  847.   pointerNum = BIG_ARROW_POINTER;           // signal using BIG_ARROW_POINTER
  848.   setupMousePointer(pointerNum);            // make BIG_ARROW_POINTER active
  849.   showMouse();                              // show the pointer
  850.  
  851.   //*** Main loop
  852.   while (!kbhit())
  853.   {
  854.     //*** Button pressed; change to BIG_TARGET_POINTER
  855.     if (buttonMouse() && pointerNum!=BIG_TARGET_POINTER)
  856.     {
  857.       pointerNum = BIG_TARGET_POINTER;      // signal using BIG_TARGET_POINTER
  858.       setupMousePointer(pointerNum);        // make BIG_TARGET_POINTER active
  859.     }
  860.     //*** Button released; change to BIG_ARROW_POINTER
  861.     else if (!buttonMouse() && pointerNum==BIG_TARGET_POINTER)
  862.     {
  863.       pointerNum = BIG_ARROW_POINTER;       // signal using BIG_ARROW_POINTER
  864.       setupMousePointer(pointerNum);        // make BIG_ARROW_POINTER active
  865.     }
  866.   }
  867.  
  868.   //*** Shut off mouse handler
  869.   deInitNewMouse();
  870. }
  871.  
  872.  
  873.  
  874. /**************************************************************************
  875. *  Function:    signOff
  876. *
  877. *  Purpose:     Print a sign-off message.
  878. *
  879. *  Entry:       N/A
  880. *
  881. *  Exit:        N/A
  882. **************************************************************************/
  883.  
  884. void signOff(void)
  885. {
  886.   static char notice[] =
  887.   {
  888.     "⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø"
  889.     "≥ The Graphics Engine 1.33 Demo  Copyright (c) 1993-1994 by Matthew Hildebrand ≥"
  890.     "ΔÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕµ"
  891.     "≥ Although this program is not particularly gripping, it demonstrates TGE's    ≥"
  892.     "≥ speed and most of its many features.  TGE is especially suited to device-    ≥"
  893.     "≥ independence, as can be seen by running this demo with different drivers,    ≥"
  894.     "≥ though it may of course be used in single-mode programs as well.             ≥"
  895.     "≥                                                                              ≥"
  896.     "≥ TGE has many features, including:                                            ≥"
  897.     "≥      ˛ Use of loadable graphics drivers and loadable fonts                   ≥"
  898.     "≥      ˛ A powerful set of graphical functions                                 ≥"
  899.     "≥      ˛ Support for viewports, or clipping regions                            ≥"
  900.     "≥      ˛ Support for virtual screens of varying sizes                          ≥"
  901.     "≥      ˛ Extensive mouse support, including definable pointers                 ≥"
  902.     "≥      ˛ Graphics output using COPY, AND, NOT, OR, and XOR                     ≥"
  903.     "≥      ˛ Native support for both PCX files and TGE-format RAW files            ≥"
  904.     "≥                                                                              ≥"
  905.     "≥ TGE costs only $30 US funds or $40 Canadian funds; paid users are entitled   ≥"
  906.     "≥ to free upgrades, technical support, royalty-free distribution rights,       ≥"
  907.     "≥ complete source code, and eternal happiness.  Refer to TGE.DOC for details.  ≥"
  908.     "ΔÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕµ"
  909.     "≥ Matthew Hildebrand, 4 College St., St. Catharines, Ontario, Canada, L2R 2W7  ≥"
  910.     "¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ"
  911.   };
  912.  
  913.   printf(notice);                           // print the message
  914. }
  915.  
  916.  
  917.  
  918. /**************************************************************************
  919. *  Function:    getKey
  920. *
  921. *  Purpose:     Get a character from the keyboard.  This function differs
  922. *               from getch() in that it can correctly handle extended keys
  923. *               such as the function keys.
  924. *
  925. *  Entry:       N/A
  926. *
  927. *  Exit:        Returns the keycode of the key pressed.
  928. **************************************************************************/
  929.  
  930. int getKey(void)
  931. {
  932.   int ch;
  933.  
  934.   ch = getch();                             // get a byte
  935.   if (!(ch & 0xFF))                         // is it zero?
  936.     ch = getch() << 8;                      // yes, get another byte
  937.   return (ch);                              // return the keycode
  938. }
  939.  
  940.  
  941.  
  942. /**************************************************************************
  943. *  Function:    waitVerticalRetrace
  944. *
  945. *  Purpose:     Wait for the start of a new vertical retrace.
  946. *
  947. *  Entry:       N/A
  948. *
  949. *  Exit:        N/A
  950. **************************************************************************/
  951.  
  952. void waitVerticalRetrace(void)
  953. {
  954.   //*** Wait for any current vertical retrace to end.
  955.   asm mov   dx,3DAh
  956.           WaitVerticalRetrace1:
  957.   asm in    al,dx                           // get status
  958.   asm and   al,08h
  959.   asm jnz   WaitVerticalRetrace1            // loop if necessary
  960.  
  961.   //*** Wait for the start of the next vertical retrace.
  962.   asm mov   dx,3DAh
  963.           WaitVerticalRetrace2:
  964.   asm in    al,dx                           // get status
  965.   asm and   al,08h
  966.   asm jz    WaitVerticalRetrace2            // loop if necessary
  967. }
  968.